/**
 * Copyright 厦门中软海晟信息技术有限公司 版权所有 违者必究 2019
 */
package com.opencvjava.lessons.core;

import org.opencv.core.Mat;
import org.springframework.stereotype.Service;

import static com.opencvjava.support.util.CvUtils.imshow;
import static com.opencvjava.support.util.CvUtils.mat;
import static org.opencv.imgproc.Imgproc.*;
import static org.opencv.imgcodecs.Imgcodecs.*;
import static org.opencv.core.Core.*;

/**
 * @author : sunzb(sunzb@hsit.com.cn)
 * @date: 2019/1/4
 */
@Service
public class L6_AddingTwoImages {
    public void test() {
        double alpha = 0.9; double beta;
        Mat src1 = mat("lena.jpg");
        if (src1.empty() == true) {
            throw new RuntimeException("Error loading src1");
        }
        imshow("源图", src1);
        Mat src2 = new Mat();
        // 按位取反 x = 255 - x
        bitwise_not(src1, src2);
        imshow("biwise_not", src2);
        beta = (1.0 - alpha);
        Mat dst = new Mat();
        // clamp((alpha * x1 + beta * x2) / 2 + gamma) =
        // clamp((0.9 * x1 + 0.1 * x2)/2 + 10) =
        // clamp((0.9 * x1 + 0.1 * (255 - x1))/2 + 10) =
        // clamp(0.8 * x1 + 25.5 + 10)
        addWeighted(src1, alpha, src2, beta, 10, dst);
        System.out.println("10, 10 : " + dst.get(10, 10)[0]);
        System.out.println("20, 20 : " + dst.get(20, 20)[0]);
        imshow("Linear Blend", dst);
    }
}
